package com.EAIPClub.userdatamanager.mapper;

import com.api.POJO.UserDataManager.Data.User;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Description :用户基本信息Mapper
 * @Author :崔昌赫
 * @Date : 2021/10/10
 */
@Mapper
@Repository
public interface UserBaseDataMapper {
    @Select("SELECT * FROM users")
    List<User> findAllUserBaseData();
    @Select("SELECT * FROM users WHERE uid='${uid}'")
    User findUserBaseDataByUid(@Param("uid") String uid);
    @Select("SELECT * FROM users WHERE email='${email}'")
    User findUserBaseDataByEmail(@Param("email") String email);
    @Select("SELECT * FROM users WHERE password='${password}'")
    List<User> findUserBaseDataByPassword(@Param("password") String password);

    @Insert("INSERT INTO users VALUES (null,'${user.uid}','${user.email}','${user.password}')")
    Boolean addUserIntoUserBaseData(@Param("user") User user);

    @Update("UPDATE users SET uid = '${nuid}' WHERE uid='${uid}'")
    Boolean updateUserBaseDataUidByUid(@Param("nuid")String nuid,@Param("uid")String uid);
    @Update("UPDATE users SET uid = '${nuid}' WHERE email='${email}'")
    Boolean updateUserBaseDataUidByEmail(@Param("nuid")String nuid,@Param("email")String email);
    @Update("UPDATE users SET email = '${nemail}' WHERE uid='${uid}'")
    Boolean updateUserBaseDataEmailByUid(@Param("nemail")String nuid,@Param("uid")String uid);
    @Update("UPDATE users SET email = '${nemail}' WHERE email='${email}'")
    Boolean updateUserBaseDataEmailByEmail(@Param("nemail")String nuid,@Param("email")String email);
    @Update("UPDATE users SET password = '${npassword}' WHERE uid='${uid}'")
    Boolean updateUserBaseDataPasswordByUid(@Param("npassword")String nuid,@Param("uid")String uid);
    @Update("UPDATE users SET password = '${npassword}' WHERE email='${email}'")
    Boolean updateUserBaseDataPasswordByEmail(@Param("npassword")String nuid,@Param("email")String email);

    @Delete("DELETE FROM users WHERE id = '${id}'")
    Boolean deleteUserBaseDataById(@Param("id")Integer id);
    @Delete("DELETE FROM users WHERE uid='${uid}'")
    Boolean deleteUserBaseDataByUid(@Param("uid")String uid);
    @Delete("DELETE FROM users WHERE email = '${email}'")
    Boolean deleteUserBaseDataByEmail(@Param("email")String email);
    @Delete("DELETE FROM users WHERE password = '${password}'")
    Boolean deleteUserBaseDataByPassword(@Param("password")String password);
}
